﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Diagnostics;
using Daphne.Modularity.UI;
using Daphne.ControlsMetro.Clock;
using Daphne.SharedMetro;
using Microsoft.Practices.Unity;
using Daphne.PagesMetro.Pages;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace DaphneMetro
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : PageBase
    {
        [Dependency]
        private IClock _clock
        { get; set; }

        public MainPage()
        {
            InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }

        protected override void GoForwardFired()
        {
            if (Frame.CanGoForward)
                Frame.GoForward();

            base.GoForwardFired();
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ClockSettings settings = new ClockSettings();
            settings.ClockType = eClockType.ControlForGame;
            settings.MinutesForGame = 40;
            settings.MinutesForMove = new MinutesForMove[0];
            _clock.Init(settings);
            _clock.Start();

            uxSwitch.Tapped += uxSwitch_Tapped;
            uxPause.Tapped += uxPause_Tapped;
            uxResume.Tapped += uxResume_Tapped;
            uxEditor.Tapped += uxEditor_Tapped;
            uxLicenses.Tapped += uxLicenses_Tapped;
        }

        void uxLicenses_Tapped(object sender, TappedRoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(LicensesPage));
        }

        void uxEditor_Tapped(object sender, TappedRoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(EditorPage));
        }

        void uxResume_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _clock.Resume();
        }

        void uxPause_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _clock.Pause();
        }

        void uxSwitch_Tapped(object sender, TappedRoutedEventArgs e)
        {
            _clock.ChangeSTM();
        }

    }
}
